#include "connexion.h"
#include "ui_connexion.h"

#include "mainwindow.h"

connexion::connexion(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::connexion)
{
    ui->setupUi(this);
    r = new Reseau();
    w = new MainWindow();
    w->setReseau(r);    
}

connexion::~connexion()
{
    delete ui;
    delete w;
    delete r;
}

void connexion::on_connexion_2_clicked()
{

    if(!ui->ip->text().isEmpty() && !ui->pseudo->text().isEmpty())
    {
        this->pseudo = ui->pseudo->text();
        w->show();
        r->envoyerDonnees(this->pseudo + r->connecte(ui->ip->text()));
        w->setPseudo(this->pseudo);
        r->envoyerDonnees(tr("&") + this->pseudo + tr("&"));
        this->hide();
    }
}
void connexion::on_annuler_clicked()
{
    exit(1);
}
